using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;


namespace ESWebFramework.I18N
{
    /// <summary>
    /// <para>
    /// ESi18nCancelButton is web control which provides you with a simple way 
    /// (using the properties window) of configuring a button which does not 
    /// post back and forwards the user to the previous page. The only thing that
    /// needs to be set is <code>CancelURL</code>
    /// </para>
    /// <para>Also this control implements the Internationalization code
    /// which is specific to all ESWebFramework components. You just type
    /// in the TextReference and the Text propery of the button is translated
    /// automatically</para>
    /// </summary>
    /// <remarks>
    /// If you configure the button as Auto</remarks>
    [DefaultProperty("TextReference")]
    [ToolboxData("<{0}:ESi18nCancelButton runat=server></{0}:ESi18nCancelButton>")]
    public class ESi18nCancelButton : Button
    {
        /// <summary>
        /// Reference string by which a lookup in the text database should
        /// performed to locate the display string
        /// </summary>
        public string TextReference
        {
            get
            {
                String s = (String)ViewState["TextReference"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["TextReference"] = value;
            }
        }
        
        /// <summary>
        /// URL formatted string to which the user will be transfered after clicking cancel
        /// </summary>
        public string CancelURL
        {
            get
            {
                String s = (String)ViewState["CancelURL"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["CancelURL"] = value;
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            ESWebUserControl father = ESWebUserControl.checkParentType(this);
            if(father == null)
                throw(new Exception( "Wrong type of Parent! The Parent control can not be casted correctly. "+
                        "The controls from the ESWebFramework library needs to be placed on a user"+
                        " control which inherits from ESWebUserControl."));

            if (TextReference != "" || TextReference != null)
                Text = TextBaseFactory.loadText(TextReference, father.LangId);

        }
    }
}